Skip to main content
Version: 1.0.160

Google Signin

Here is a simple example of creating googleSignIn custom module.

Install

Install and setup react-native-google-signin/google-signin package from here. After that, create a file named google-signin.js and paste below code.

google-signin.js
import { GoogleSignin, statusCodes, GoogleSigninButton } from '@react-native-google-signin/google-signin';


export default {
GoogleSignin, statusCodes, GoogleSigninButton
}

And include the googleSignIn in NanoApp componenent like below

import {NanoApp} from  'react-native-nano';
import googleSignIn from 'google-signin';


const customGoogleSignInPackage = {
name:'my_custom_package',
appStart: () => {
},
modules:[{
name:'googleSignIn', // name to access module in `moduleParams`
module:googleSignIn, // actual module
}]
};

const App = () => {
return <NanoApp
packages={[customGoogleSignInPackage]}
// ..other props
/>;
};
export default App;

And use the googleSignIn module from any method like below.

const buttonPress = {
component: NANO.BUTTON,
value: 'SIGN IN',
onPress: ({ moduleParams }) => {
const googleSignIn = moduleParams['googleSignIn'];

googleSignIn["GoogleSignin"].hasPlayServices()
.then(() => {
 
googleSignIn["GoogleSignin"].signIn()
.then((userInfo) => {}).catch((error) => {});

})
.catch((error) => {
if (error.code === googleSignIn["statusCodes"].SIGN_IN_CANCELLED) {
console.log("SIGN_IN_CANCELLED")
} else if (error.code === googleSignIn["statusCodes"].IN_PROGRESS) {
console.log("IN_PROGRESS")
} else if (error.code === googleSignIn["statusCodes"].PLAY_SERVICES_NOT_AVAILABLE) {
console.log("PLAY_SERVICES_NOT_AVAILABLE")
} else {
console.log("UNKNOWN")
}
console.log(error)
});
}
};

const screen = {
name: 'HomeScreen',
screen: {
h1: [buttonPress],
}
};